#include "head.h"
#include "cc9d_support.h"
#include "handshake.h"
#include "stm32f10x.h"

#define LOCAL_PORT Handshake_PORT
#ifndef printd
#define printd(...)
#endif

extern const char* const App_name_strl;

void Handshake_recvPkg(sCc9dPkg* pkg, uint8 data_len) {
	if (data_len == 0) {
		return;
	}
	switch (pkg->datas[0]) {
	case '-': {//发送自己的名字
		sCc9dPkg send_pkg;
		createResponsePkg(&send_pkg, pkg);
		send_pkg.datas[0] = '-';
		int i = 0;
		for (;App_name_strl[i] != 0;i++) {
			send_pkg.datas[i + 1] = App_name_strl[i];
		}
		cc9d_SendPkg(&send_pkg, i + 1);		
	}break;
	default:
	break;
	}	
}

static void hardBeat() {
	//发送一个心跳包报告自身存在
	sCc9dPkg send_pkg;
	send_pkg.from_port = LOCAL_PORT;
	send_pkg.to_port = 0;
	send_pkg.remote_addr = 0;
	send_pkg.datas[0] = 'H';
	cc9d_SendPkg(&send_pkg, 1);
}
void Handshake_msTick(void) {
	if (main_Clk % (7200 * 1000) == 3000) {
		hardBeat();
	}
}

void Handshake_init() {


}


